<!DOCTYPE html>
<html>

<head>
    <title>个人页面</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userProfiles.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            jQuery.ajaxSettings.traditional = true;

            var param = getParams();
            $.get("/users/" + param.id, function (data) {
                $("#coverImgUrl").css("background-image", "url(" + data.coverImgUrl + ")");
                $("#user").renderValues(data)
            })

            var aa;//游记id
            var bb;//游记点赞的总数量
            var travelId = [];//所有游记的id

            var currentPage = 1;
            var travelsDate = [];
            var pages;
            var flag = false;//表示当前没有在查询

            var commentDate = [];
            var currentPage1 = 1;
            var pages1;
            var flag1 = false;//表示当前没有在查询
            $(function () {
                function loadTravels() {
                    if (flag) {
                        return;
                    }
                    flag = true;
                    $.get("/users/" + param.id + "/travels", {currentPage: currentPage}, function (data) {

                        //所有游记的id
                        for (var i = 0; i < data.list.length; i++) {
                            travelId.push(data.list[i].id);
                        }


                        var travelNum = data.total;
                        $("#travelNum").html(travelNum);
                        $.merge(travelsDate, data.list);
                        var ret = {"list": travelsDate}
                        $("#travels").renderValues(ret, {
                            getHref: function (item, value) {
                                var href = $(item).data("href");
                                $(item).prop("href", href + value);
                            },
                            getId: function (item, value) {
                                $(item).attr("data-tid", value);
                            }
                        });


                        //查询有被点赞的游记和点赞的数量
                        $.get("/praises/praiseTravelNum", {travelId: travelId, type: 1}, function (data) {
                            var tt = $(".abc");
                            for (var a = 0; a < data.length; a++) {
                                aa = data[a].travelId;//有赞的游记
                                bb = data[a].count;//数量

                                //回显点赞的数量
                                for (var i = 0;i<tt.length;i++){
                                    var tid = $(tt[i]).data("tid");
                                    if (tid==aa){
                                        $(tt[i]).html(bb);
                                    }
                                }
                            }
                        })
                        currentPage++
                        pages = data.pages;
                        flag = false;//表示查询完成
                    });
                }

                loadTravels();

                $(window).scroll(function () {
                    if ($(window).height() + $(document).scrollTop() + 1 >= $(document).height()) {
                        if (pages >= currentPage) {
                            loadTravels();
                        } else {
                            $(document).dialog({
                                type: 'notice',
                                infoText: '亲,到底了',
                                autoClose: 2500,
                                position: 'bottom'
                            });
                        }
                    }
                })
            })


            //点评
            $.get("/users/" + param.id + "/comments", {currentPage: currentPage1}, function (data) {
                $.merge(commentDate, data.list);
                var ret = {"list": commentDate}
                $("#comments").renderValues(ret, {
                    getHref: function (item, value) {
                        var href = $(item).data("href");
                        $(item).prop("href", href + value);
                    }

                });
                //数量
                $("#num1").html(data.total)

                $(".container").renderValues(data, {
                    getHref: function (item, value) {
                        var href = $(item).data("href")
                        $(item).prop("href", href + value);
                    },
                    getStar: function (item, value) {
                        var temp = "";
                        for (var i = 0; i < value; i++) {
                            temp += '<i class="fa fa-star"></i>';
                        }
                        for (var i = 0; i < 5 - value; i++) {
                            temp += ' <i class="fa fa-star-o"></i>';
                        }
                        $(item).html(temp);
                    }
                })

                //给图片绑定点击事件
                $(".comment-img li img").click(function () {
                    var img = $(this).attr("src");
                    $(document).dialog({
                        overlayClose: true,
                        titleShow: false,
                        content: '<img class="info-icon" width="100%" src="' + img + '"/>'
                    });
                })
                currentPage1++
                pages1 = data.pages;
                flag1 = false;//表示查询完成
            });

            function nums() {
                $.get('/users/' + param.id, function (data) {
                    $('#fans').html(data.fans);//粉丝数
                    $('#attention').html(data.attention);//关注数
                });
            }

            var user = JSON.parse(sessionStorage.getItem("user"));
            if (user) {
                //点击关注按钮发送请求添加中间表的关系
                $('#followBtn').click(function () {
                    $.post("/users/attention", {
                        attentionuserId: user.id,
                        beattentionuserId: param.id
                    }, function (data) {
                        if (data.success) {
                            $('#followBtn').html("关注");
                        } else {
                            $('#followBtn').html("取消关注");
                        }
                        nums();
                    });
                });
                nums();
            } else {
                window.location.href = "/login.html"
            }
            //查询是否是关注状态
            $.get('/users/isAttention', {attentionuserId: user.id, beattentionuserId: param.id}, function (data) {
                // console.log(data);
                if (data.success) {
                    $('#followBtn').html("取消关注");
                } else {
                    $('#followBtn').html("关注");
                }
            })
        })
    </script>
</head>
<body>
<div id="user">
    <div class="container bg" id="coverImgUrl" style="background-image: url(&quot;/img/user/bg.jpeg&quot;);">
        <a href="javascript:window.history.go(-1)" class="my-arrow">
            <span><i class="fa fa-chevron-left fa-2x"></i></span>
        </a>
        <div class="container">
            <div class="info">
                <img class="rounded-circle" width="17%" render-src="headImgUrl">
                <p class="name" render-html="nickName"></p>
                <p render-html="sign"></p>

                <div class="row num">
                    <div class="col-2 border border-left-0 border-top-0 border-bottom-0">
                        <div>
                            <span id="fans"></span>
                        </div>
                        <div>
                            <span>关注</span>
                        </div>
                    </div>
                    <div class="col-2">
                        <div>
                            <span id="attention"></span>
                        </div>
                        <div>
                            <span>粉丝</span>
                        </div>
                    </div>
                    <div class="col">
                        <button class="btn btn-primary-light ibtn" id="letterBtn">私信</button>
                        <script>
                            $("#letterBtn").click(function () {
                                window.location.href = "/mine/privateLetter.html?id=" + getParams().id;
                            })
                        </script>
                        <button class="btn btn-success ibtn" id="followBtn">关注</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="tabs">
    <ul class="nav nav-pills nav-justified  border border-left-0 border-top-0 border-right-0" id="pills-tab"
        role="tablist">
        <li class="nav-item">
            <a class="nav-link active" id="travels-tab" data-toggle="pill" href="#travels">
                TA的游记[<span id="travelNum"></span>]
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link comment" id="comments-tab" data-toggle="pill" href="#comments">
                TA的点评[<span id="num1"></span>]
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-contact">
                TA的旅行单[<span>0</span>]
            </a>
        </li>
    </ul>
    <div class="container tab-content" id="pills-tabContent">
        <div class="tab-pane fade show active" id="travels">
            <dl class="list" render-loop="list">
                <dd>
                    <a data-href="travelContent.html?id=" render-key="list.id" render-fun="getHref">
                        <img render-src="list.coverUrl">
                        <p>
                            <span class="title" render-html="list.title"></span>
                            <span class="span-right">
										<span class="abc" render-key="list.id" render-fun="getId">0</span>
										<i class="fa fa-thumbs-o-up"></i>
									</span>
                        </p>
                    </a>
                    <hr>
                </dd>
            </dl>
        </div>

        <div class="comment tab-pane fade " id="comments">
            <div render-loop="list">
                <div class="row">
                    <div class="col-2 comment-head">
                        <img class="rounded-circle" render-src="list.user.headImgUrl">
                    </div>
                    <div class="col">
								<span class="comment-star" render-key="list.starNum" render-fun="getStar">

								</span>

                        <span class="comment-date" render-html="commendTime"></span>
                        <div class="comment-content">
                            <a data-href="/mine/strategyComment.html?id=" render-key="list.id" render-fun="getHref">
                                <p render-html="list.content"></p>
                            </a>
                        </div>
                        <ul class="comment-img" render-loop="list.imgArr">
                            <li>
                                <img render-src="list.imgArr.self">
                            </li>

                        </ul>

                        <div class="comment-link">
                            <a data-href="/strategyCatalogs.html?id=" render-key="list.strategy.id"
                               render-fun="getHref">
                                <img render-src="list.strategy.coverUrl"> <span
                                    render-html="list.strategy.title"></span>
                                <i class="fa fa-angle-right fa-2x"></i>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="tab-pane fade" id="pills-contact">.3333..</div>
    </div>
</div>
</body>
</html>